/**
 * Copyright (C) 2018-2019
 * All rights reserved, Designed By www.joolun.com
 * 注意：
 * 本软件为www.joolun.com开发研制，项目使用请保留此说明
 */
package com.ruoyi.mall.admin.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.mall.api.RemoteUserAddressService;
import com.ruoyi.mall.api.entity.UserAddress;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.*;

/**
 * 用户收货地址
 *
 * @author JL
 * @date 2019-09-11 14:28:59
 */
@Slf4j
@RestController
@RequestMapping("/useraddress")
@Api(value = "useraddress", tags = "用户收货地址管理")
public class UserAddressController extends BaseController {
    @DubboReference
    private RemoteUserAddressService userAddressService;

    /**
     * 分页查询
     *
     * @param page        分页对象
     * @param userAddress 用户收货地址
     * @return
     */
    @ApiOperation(value = "分页查询")
    @GetMapping("/page")
    @SaCheckPermission("mall:useraddress:index")
    public R getUserAddressPage(Page page, UserAddress userAddress) {
        return R.ok(userAddressService.page(page, userAddress));
    }

    /**
     * 通过id查询用户收货地址
     *
     * @param id
     * @return R
     */
    @ApiOperation(value = "通过id查询用户收货地址")
    @GetMapping("/{id}")
    @SaCheckPermission("mall:useraddress:get")
    public R getById(@PathVariable("id") String id) {
        return R.ok(userAddressService.getById(id));
    }

    /**
     * 新增用户收货地址
     *
     * @param userAddress 用户收货地址
     * @return R
     */
    @ApiOperation(value = "新增用户收货地址")
    @PostMapping
    @SaCheckPermission("mall:useraddress:add")
    public R save(@RequestBody UserAddress userAddress) {
        return R.ok(userAddressService.save(userAddress));
    }

    /**
     * 修改用户收货地址
     *
     * @param userAddress 用户收货地址
     * @return R
     */
    @ApiOperation(value = "修改用户收货地址")
    @PutMapping
    @SaCheckPermission("mall:useraddress:edit")
    public R updateById(@RequestBody UserAddress userAddress) {
        return R.ok(userAddressService.updateById(userAddress));
    }

    /**
     * 通过id删除用户收货地址
     *
     * @param id
     * @return R
     */
    @ApiOperation(value = "通过id删除用户收货地址")
    @DeleteMapping("/{id}")
    @SaCheckPermission("mall:useraddress:del")
    public R removeById(@PathVariable String id) {
        return R.ok(userAddressService.removeById(id));
    }

}
